import java.util.LinkedList;
import java.util.Queue;
import java.util.Random;


public class AlgoritmPTG
{
	public static int test(boolean [] viz)
	{
		for(int i=0;i<viz.length;i++)
			if(viz[i] == false)
				return i;
		return -1;
	}
	
	public static int test(int [] v)
	{
		for(int i=0;i<v.length;i++)
			if(v[i] == 1)
				return i;
		return -1;
	}
	
	public static String getParcurgere(GrafOrientat g)
	{
		String s="";
		boolean [] viz = new boolean[g.getNrVarfuri()]; 
		int [] v = new int [g.getNrVarfuri()];
		
		s+=" 0";
		viz[0] = true;
		v[0] = 1;
		int x=0;
		
		while(test(viz) != -1)
		{
			
			if(test(v) == -1)
			{
				v[(test(viz))]=1;
				s=s+" "+String.valueOf(test(viz));
				viz[test(viz)] = true;
			}
			while(test(v) != -1)
			{
				Random r = new Random();
				System.out.println(x);
				do
				{
					x = r.nextInt(g.getNrVarfuri());
				}
				while(v[x] == 0 );
			
				//v[x] = 0;
				boolean ok = false;
				
				for(int i=0; i < g.getNrElem(x) ;i++)
					if(viz[g.getListaAd(x).get(i)] == false)
					{
						v[g.getListaAd(x).get(i)] = 1;
						viz[g.getListaAd(x).get(i)] = true;
						s+=" ";
						s+=g.getListaAd(x).get(i);
						ok = true;
						break;
					}
				if(ok == false)
					v[x] = 0;
			}
		}
		return s;
	}

}
